<template>
  <div class="hourly-item">
    <i class="icon" :style="{backgroundImage:`url('${icon}')`}"></i>
    <b class="text">{{text}}</b>
    <b class="tmp">{{data.tmp}}°C</b>
    <b class="time">{{time}}</b>
  </div>
</template>

<script>
import { getWeatherObj } from '@/tools'

export default {
  name: 'hourly-item',
  props: {
    data: {
      type: Object,
      required: true
    }
  },
  computed: {
    icon() {
      return getWeatherObj(this.data.wc).icon
    },
    text() {
      return getWeatherObj(this.data.wc).text
    },
    time() {
      const h = new Date(this.data.time).getHours()
      return `${h % 12}:00 ${h < 12 ? 'am' : 'pm'}`
    }
  }
}
</script>

<style lang="stylus">
$size = 40px;

.hourly-item {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  width: 28%;
  min-width: 8em;
  font-size: 14px;

  .icon {
    width: $size;
    height: $size;
    background: center / cover no-repeat;
  }

  .icon, .text, .tmp {
    margin-bottom: 0.5em;
  }
}
</style>
